package com.tianzeculture.stagebao.activity.artist;

import android.content.Intent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.base.BaseActivity;
import com.tianzeculture.stagebao.dialog.UnitDialog;
import com.tianzeculture.stagebao.net.CommonRestUsage;
import com.tianzeculture.stagebao.network.Request;
import com.tianzeculture.stagebao.network.enity.MSG;
import com.tianzeculture.stagebao.network.util.ToastUtil;
import com.tianzeculture.stagebao.util.Util;

import butterknife.BindView;
import butterknife.OnClick;

import static com.tianzeculture.stagebao.util.Util.WORK_BREAKDOWN;
import static com.tianzeculture.stagebao.util.Util.WORK_TYPE;

/**
 * Created by Administrator on 2018/6/29 0029.
 * 加入人才库-添加我的报价
 */

public class ArtistEditPriceDetailActivity extends BaseActivity {
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvRight)
    TextView tvRight;

    @BindView(R.id.tvWorkType)
    TextView tvWorkType;
    @BindView(R.id.tvWorkBreakdown)
    TextView tvWorkBreakdown;
    @BindView(R.id.tvPriceUnit)
    TextView tvPriceUnit;
    @BindView(R.id.tvWorkPrice)
    EditText tvWorkPrice;

    @Request
    CommonRestUsage commonRestUsage = null;
    private int getWorkTypeList = 101;//获取工作类型列表
    private int addOffer = 102;//添加报价
    String workType;
    String workBreakdown;

    @Override
    public void initUI() {
        super.initUI();
        tvTitle.setText("添加报价");
        tvRight.setText("保存");
        tvRight.setVisibility(View.VISIBLE);
    }

    @Override
    protected void onResume() {
        super.onResume();
//        commonRestUsage.workTypeList(getWorkTypeList);
    }

    @OnClick({R.id.tvWorkType, R.id.tvWorkBreakdown, R.id.tvPriceUnit, R.id.tvWorkPrice, R.id.tvRight})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tvWorkType://工作类型
                startActivityForResult(new Intent(this, WorkTypeActivity.class), WORK_TYPE);
                break;
            case R.id.tvWorkBreakdown://工作细分
                startActivityForResult(new Intent(this, WorkBreakDownActivity.class), WORK_BREAKDOWN);
                break;
            case R.id.tvPriceUnit://报价单位
//                UnitDialog unitDialog = new UnitDialog(this);
//                unitDialog.setOnSelectClickListener(new UnitDialog.OnSelectClickListener() {
//                    @Override
//                    public void onOk(boolean isDay) {
//                        if (isDay) {
//                            tvPriceUnit.setText("每天");
//                        } else {
//                            tvPriceUnit.setText("每小时");
//                        }
//                    }
//
//                    @Override
//                    public void onCancel() {
//
//                    }
//                });
//                unitDialog.show();
                break;

            case R.id.tvRight:
                if (tvWorkPrice.getText() == null) {
                    ToastUtil.showShort(this, "通告报价不能为空");
                    return;
                }
                commonRestUsage.addOffer(addOffer, workType, workBreakdown, tvPriceUnit.getText().toString(), tvWorkPrice.getText().toString());
                break;
//            case R.id.tvWorkPrice://通告报价
//
//                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case WORK_TYPE:
                workType = data.getExtras().getString("WORK_TYPE");
                tvWorkType.setText(workType);
                break;
            case WORK_BREAKDOWN:
                workBreakdown = data.getExtras().getString("WORK_BREAKDOWN");
                tvWorkBreakdown.setText(workBreakdown);
                break;
        }
    }

    @Override
    public void refreshUI(int taskId, MSG msg) {
        super.refreshUI(taskId, msg);
        if (taskId == addOffer) {
            if (msg.getData()) {
                finish();
            }
            dismissProgressDialog();
        }
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_edit_price_detail;
    }
}
